<template>
	<view :class="[BackGround]" :style="[{'font-weight':Style,'font-family':Font,height:100 + '%',minHeight:height + 'px'}]">
		<cu-custom bgColor="bg-gradual-blue" isBack="true">
			<view slot="backText">返回</view>
			<view slot="content">粗纱落纱分析报表</view>
		</cu-custom>
		<sear-ch :placeholder="placeholder" @clean="clean" @input="input" @remove="remove" :message="message"></sear-ch>
		<screen-view ref="screen" @formSubmit="formSubmit" :isShow="false" :screenisShow="true" :searchisShow="false">
			<view v-if="isShow">
				<view class="cu-form-group">
					<view class="title">车间</view>
					<picker @change="PickerChange1" name="LCLASSINDEX" :value="index1" :range="picker1" range-key="LNAME">
						<view class="picker">
							{{index1 == -1 ? '请选择' : picker1[index1].LNAME}}
						</view>
					</picker>
				</view>
				<view class="cu-form-group">
					<view class="title">机器号</view>
					<picker @change="PickerChange2" name="LMACHINENO" :value="index2" :range="picker2" range-key="LMACHINENO">
						<view class="picker">
							{{index2 == -1 ? '请选择' : picker2[index2].LMACHINENO}}
						</view>
					</picker>
				</view>
			</view>
		</screen-view>
		<mix-pulldown-refresh ref="mixPulldownRefresh" :top="CustomBar + 100" :scrolltopa="scrollTop" @refresh="onPulldownReresh"
		 @setEnableScroll="setEnableScroll" @scroll='scroll'>
			<z-table :tableData="deliverplanDoffing" :stickSide="false" :showSelect="false" :showBottomSum="false" :columns="finaleColumnsDoffing"
			 @onSort="doSort" @onSelect="tableSelect" :num="0" :bottom="180"></z-table>
			<mix-load-more :status="2" v-if="!isFlag"></mix-load-more>
		</mix-pulldown-refresh>
		<!-- #ifdef APP-PLUS -->
		<view class="table-fixed" @tap="switchP">
			<image :class="[imgclass]" src="/static/images/phoneicon.png" mode="aspectFill"></image>
		</view>
		<!-- #endif -->
		<button class="cu-btn bg-gradual-blue lg shadow tb-flex cu-btn-new fixed_Export" @tap="Export">导出</button>
	</view>
</template>

<script>
	import SearCh from "@/colorui/components/search.nvue";
	import ScreenView from '@/colorui/components/ScreenView.vue'
	import zTable from "@/colorui/components/z-table.vue";
	import utils from '@/static/js/utils.filter.js';
	import mixPulldownRefresh from '@/colorui/components/mixpulldownrefresh.vue'
	import mixLoadMore from '@/colorui/components/mixloadmore';
	import {
		mapGetters
	} from "vuex";
	import {
		scrollrefresh,
		inputSearch,
		viewTable,
		tableFixed
	} from "@/mixin/mixin.js"
	import {
		getReport,
		getselectReferList,
		getSelect2
	} from "@/service/selectList"
	import {
		generateExcel
	} from "@/service/insert.js"
	export default {
		mixins: [viewTable, inputSearch, tableFixed, scrollrefresh],
		data() {
			return {
				placeholder: "员工姓名",
				height: this.screenHeight,
				message: '筛选',
				dateleft: global.startbefore,
				dateright: global.dateright,
				searchView: "LUSERNAME",
				searchCondition: [{
					name: '员工姓名',
					code: 'LUSERNAME',
					checked: true
				}],
				isFlag: false,
				deliverplanDoffing: [],
				isShow: false,
				picker2: [],
				index1: 0,
				index2: 0,
				picker1: [],
			}
		},
		computed: {
			...mapGetters(["Style", 'Font', 'BackGround', 'BackGroundBox'])
		},
		components: {
			SearCh,
			ScreenView,
			zTable,
			mixPulldownRefresh,
			mixLoadMore
		},
		onResize() {
			uni.getSystemInfo({
				success: function(res) {
					console.log(res.windowWidth);
					console.log(res.windowHeight);
					if (res.windowWidth > res.windowHeight) {
						console.log('横屏');
					} else {
						console.log('竖屏');
					}
				}
			});
		},
		onLoad() {
			this.getReport()
		},
		methods: {
			PickerChange1(e) {
				this.index1 = e.detail.value
			},
			PickerChange2(e) {
				this.index2 = e.detail.value
			},
			onPulldownReresh() {
				console.log('下拉');
				this.getReport2()
			},
			async getReport() {
				let data = await getselectReferList(9538, '表头', 'LCLASSINDEX', {})
				this.picker1 = data.data
				let data2 = await getSelect2(9538, {})
				this.picker2 = data.data
				if(data.data.length>0 && data2.data.length>0) {
					let mylist = []
					data2.data.forEach((value, index) => {
						if (value['LTYPE'] == '粗纱') {
							mylist.push(value)
						}
					})
					this.picker2 = mylist
					this.isShow = true
					this.getReport2()
				}
			},
			getReport2() {
				getReport('0', this.picker2[this.index2]['LMACHINENO'], this.picker1[this.index1]['LNAME'], this.dateleft, this.dateright)
					.then(res => {
						if (res.code == 1) {
							res.data.forEach((value, index) => {
								value['isShow'] = true
							})
							this.deliverplanDoffing = res.data
							this.deliverplan = res.data
							setTimeout(() => {
								this.$refs.mixPulldownRefresh.endPulldownRefresh()
							}, 500)
						} else {
							uni.showToast({
								title: '获取数据失败！',
								icon: 'none'
							})
						}
					})
			},
			formSubmit(e) {
				this.dateleft = e.picker1
				this.dateright = e.picker2
				this.getReport2()
			},
			Export() {
				if(this.deliverplanDoffing.length > 0) {
					let mylist = []
					this.deliverplanDoffing.forEach((value,index) => {
						if(value['isShow'] == true) {
							mylist.push(value)
						}
					})
					generateExcel('LSExcelPojo',mylist).then(res => {
						if(res.code == 1) {
							plus.runtime.openURL(`http://60.173.239.156:8443/image/UserImage/${res.data}`);
						} else {
							uni.showToast({
								title:'导出失败',
								icon:'none'
							})
						}
					})
				} else {
					uni.showToast({
						title:'暂无数据无法导出',
						icon:'none'
					})
				}
				
			}
		}
	}
</script>

<style lang="scss" scoped>
.fixed_Export {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
}
</style>